﻿using System;
using System.Diagnostics;
using System.Windows.Forms;
using Campus.Main.Basic.Settings;
using Campus.Report.ReportForm;
using Microsoft.Reporting.WinForms;
using dbcntn;
using mkrpt;

namespace Campus.Main.Basic
{
    public partial class Report1 : DefaultForm
    {
        //public static string ConnectionString = "server=localhost;User Id=root;Persist Security Info=True;database=Ogrenci2006_dbo;password=123456";

        protected string q1;// = Query.OnKayit;
        protected string q2;// = Query.OnKayit;

        public Report1()
        {
            InitializeComponent();
            aToDb=new ConnectionToDb(Helper.ConnectionString);
        }
        public override void Initialize()
        {
            groupBox2.Enabled = groupBox3.Enabled = groupBox5.Enabled = groupBox6.Enabled = false;
            checkBox1.Checked = checkBox2.Checked = checkBox3.Checked = checkBox4.Checked = checkBox5.Checked = false;
            rbt_burs_can_k.Checked =
                rbt_burs_can_o.Checked =
                rbt_burs_ok_k.Checked =
                rbt_burs_ok_o.Checked =
                rbt_pol_e_k.Checked = rbt_pol_k_k.Checked = rbt_uyr_e_o.Checked = rbt_uyr_k_o.Checked = false;
            q1 = Query.OnKayit;
            q2 = Query.KesinKayit;
            //rbt_burs_can_o.Checked = rbt_burs_ok_o.Checked = rbt_uyr_e_o.Checked = rbt_uyr_k_o.Checked = false;

        }

        protected virtual void Report1_Load(object sender, EventArgs e)
        {
            Initialize();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                aToDb.AddItem(cmb_fak_list_o, "fakulty");
            }
            else
            {
                cmb_fak_list_o.DataSource = null;
            }
        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                aToDb.AddItem(cmb_uyr_list_o, "nation");
            }
            else
            {
                cmb_uyr_list_o.DataSource = null;
            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox3.Checked)
            {
                aToDb.AddItem(cmb_cource_list_o, "cource");
            }
            else
            {
                cmb_cource_list_o.DataSource = null;
            }
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkBox4.Checked)
            {
                rbt_burs_ok_o.Checked=rbt_burs_can_o.Checked = false;
                groupBox2.Enabled = false;
            }
            else
            {
                groupBox2.Enabled = true;
                rbt_burs_ok_o.Checked = true;
            }
        }

        private void checkBox5_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkBox5.Checked)
            {
                rbt_uyr_e_o.Checked = false;
                groupBox3.Enabled = false;
            }
            else
            {
                groupBox3.Enabled = true;
                rbt_uyr_e_o.Checked = true;
            }
        }

        protected virtual void btn_uyr_o_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                q1 += " and b.id =" + Convert.ToString(cmb_fak_list_o.SelectedValue);
            }
            if (checkBox2.Checked)
            {
                q1 += " and a.nation_id =" + Convert.ToString(cmb_uyr_list_o.SelectedValue);
            }
            if (checkBox3.Checked)
            {
                 q1 += " and a.Cource_id =" + Convert.ToString(cmb_cource_list_o.SelectedValue);
            }
            if (checkBox4.Checked)
            {
                if (rbt_burs_ok_o.Checked)
                {
                    q1 += " and a.oratalama>=2.5";
                }
                if (rbt_burs_can_o.Checked)
                {
                    q1 += " and a.oratalama<2.5";
                }
            }
            if (checkBox5.Checked)
            {
                if (rbt_uyr_e_o.Checked)
                {
                     q1+= " and a.pol_id=1";
                }
                if (rbt_uyr_k_o.Checked)
                {
                     q1+= " and a.pol_id=2";
                }
            }
            aToDb.AddItemDBGridView(dataGridView1,q1);
            if (dataGridView1.RowCount > 0)
            {
                ReportForm f = new ReportForm();
                f.reportViewer1.ProcessingMode = ProcessingMode.Local;
                f.reportViewer1.LocalReport.ReportPath = "ReportTemplate/OnKayitReport.rdlc";
                ogrenci2006_dboDataSet1.Clear();
                f.reportViewer1.LocalReport.DataSources.Clear();
                f.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1",dataGridView1.DataSource)); //aToDb.GetDataSources(ogrenci2006_dboDataSet1, "OnKayit", q1)));
                f.FormClosed += ChildClose;
                f.ShowDialog();
                
                /*if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    AllReport allReport = new AllReport(saveFileDialog1);
                    allReport.Printreport(dataGridView1, "On Kayit Olan Ogrencilerin Listesi");
                    Process.Start(saveFileDialog1.FileName);
                    Initialize();
                }*/
            }
            else
            {
                MessageBox.Show("Берилиштер базасында жок");
                Initialize();
            }
        }

        private void ChildClose(object sender, FormClosedEventArgs e)
        {
            Initialize();
        }

        protected virtual void button3_Click(object sender, EventArgs e)
        {
            if (checkBox11.Checked)
            {
                q2 += " and f.id=" + Convert.ToString(comboBox4.SelectedValue);
            }
            if (checkBox10.Checked)
            {
                q2 += " and b.id =" + Convert.ToString(comboBox3.SelectedValue);
            }
            if (checkBox9.Checked)
            {
                q2 += " and a.nation_id =" + Convert.ToString(comboBox2.SelectedValue);
            }
            if (checkBox8.Checked)
            {
                q2 += " and a.Cource_id =" + Convert.ToString(comboBox1.SelectedValue);
            }
            if (checkBox7.Checked)
            {
                if (rbt_burs_ok_k.Checked)
                {
                    q2 += " and a.oratalama>=2.5";
                }
                if (rbt_burs_can_k.Checked)
                {
                    q2 += " and a.oratalama<2.5";
                }
            }
            if (checkBox6.Checked)
            {
                if (rbt_pol_e_k.Checked)
                {
                    q2 += " and a.pol_id=1";
                }
                if (rbt_pol_k_k.Checked)
                {
                    q2 += " and a.pol_id=2";
                }
            }
            aToDb.AddItemDBGridView(dataGridView1, q2);
            if (dataGridView1.RowCount > 0)
            {
                ReportForm f = new ReportForm();
                f.reportViewer1.ProcessingMode = ProcessingMode.Local;
                f.reportViewer1.LocalReport.ReportPath = "ReportTemplate/KesinKayitReport.rdlc";
                ogrenci2006_dboDataSet1.Clear();
                f.reportViewer1.LocalReport.DataSources.Clear();
                f.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dataGridView1.DataSource));//aToDb.GetDataSources(ogrenci2006_dboDataSet1, "KesinKayit", q2)));
                f.FormClosed += ChildClose;
                f.ShowDialog();
            }
            else
            {
                MessageBox.Show("Берилиштер базасында жок");
                Initialize();
            }
        }

        private void checkBox10_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox10.Checked)
            {
                aToDb.AddItem(comboBox3,"fakulty");
            }
            else
            {
                comboBox3.DataSource = null;
            }
        }

        private void checkBox9_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox9.Checked)
            {
                aToDb.AddItem(comboBox2, "nation");
            }
            else
            {
                comboBox2.DataSource = null;
            }
        }

        private void checkBox8_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox8.Checked)
            {
                aToDb.AddItem(comboBox1, "cource");
            }
            else
            {
                comboBox1.DataSource = null;
            }
        }

        private void checkBox7_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkBox7.Checked)
            {
                rbt_burs_ok_k.Checked = false;
                groupBox6.Enabled = false;
            }
            else
            {
                groupBox6.Enabled = true;
                rbt_burs_ok_k.Checked = true;
            }
        }

        private void checkBox6_CheckedChanged(object sender, EventArgs e)
        {
            if (!checkBox6.Checked)
            {
                rbt_pol_e_k.Checked = false;
                groupBox5.Enabled = false;
            }
            else
            {
                groupBox5.Enabled = true;
                rbt_pol_e_k.Checked = true;
            }
        }

        private void checkBox11_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox11.Checked)
            {
                aToDb.AddItem(comboBox4,"yurtdef");
            }
            else
            {
                comboBox4.DataSource = null;
            }
        }

      
    }
}
